import api from '@/config/api'
import { http } from '@/utils/request'

/**
 * 文件上传地址
 * @type {string}
 */
export const upload = `${api.common}/common/upload/file`

/**
 * 获取地区数据
 * @param id
 */
export function getRegionsById(id: string | number = 0) {
  return http.request({
    url: `${api.common}/common/region/item/${id}`,
    method: 'GET'
  })
}

export function withdrawalSettingVO() {
  return http.request({
    url: `${api.common}/common/site/withdrawal`,
    method: 'GET'
  })
}

interface QrcodeData {
  page: string
  scene: string
  check_path?: boolean
  envVersion?: 'release' | 'trial' | 'develop'
  width?: number
}

// 获取小程序二维码
export function getQrcode(data: QrcodeData) {
  return http
    .request({
      url: `${api.common}/common/region/createQrCode`,
      method: 'POST',
      data: {
        ...data,
        check_path: data.check_path ?? true,
        envVersion: data.envVersion ?? 'release',
        width: data.width ?? 430
      }
    })
    .then((response) => {
      // 修改返回数据结构
      return response.data.result.url
    })
}

// 解析小程序码中的scene真实参数
export function parseScene(id: string|number) {
  return http
    .request({
      url: `${api.common}/common/region/getCreateQrCodeValue/${id}`,
      method: 'GET'
    })
    .then((response) => {
      // 修改返回数据结构
      return response.data.result.value
    })
}
